from bs4 import BeautifulSoup

from libs.HttpHelp import HttpHelper


class ListPage:

    def getPage(self,url):
        httphelper = HttpHelper()
        pagehtml =httphelper.getByRequest(url)
        return pagehtml
    def getList(self,pageHtml):
        soup = BeautifulSoup(pageHtml, 'html.parser')
        x = soup.find(id='product-list')
        # lis= x.find(class_='item-wrap')
        lis = x.find_all('li')
        urls=[]
        for item in lis:
            a_obj = item.find('a')
            # print(a_obj)
            # print(type(a_obj))  #<class 'bs4.element.Tag'>
            # url_o = BeautifulSoup(a_obj,'html.parser')
            urls.append(a_obj['href'])

        return urls
        # print(item.attrs)
        # print(item['id'])
        # ids = item['id'].split('-')
        # print(ids)
        # asl =item.find(class_='title-selling-point')
        # print(len(asl))
        # a_obj = item.find('a')
        # print(type(a_obj))  #<class 'bs4.element.Tag'>
        # url_o = BeautifulSoup(a_obj,'html.parser')
        # print(a_obj['href'])
        # print(item.decode_contents(formatter="html"))